// pages/mys/fuwu/index.js
const app = getApp(); // 获取应用实例

Page({

  /**
   * 页面的初始数据
   */
  data: {
    dtotal: 0, 
    dlist: [],
    viewFlag: '', //all，my
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      viewFlag: options.viewFlag,
    });
    this.allList();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },

  // 获取数据
  allList: function (e) {
    var that = this;
    that.setData({
      viewFlag: 'all',
    });
    wx.request({
      method: 'POST',
      url: app.globalData.domainXcx + '/my/fuwu/list',
      data: {},
      timeout: 10000, //接口超时10S
      success: function (res) {
        res = res.data;
        console.log(res);
        if (res.code!=0) {
          wx.showToast({
            title: res.msg, icon: 'none'
          }); return
        }
        that.setData({
          dtotal: res.total,
          dlist: res.data,
        });
      },
      fail: function () {
        console.log('error');
      }
    });
  },

  // 获取数据
  myList: function (e) {
    var that = this;
    that.setData({
      viewFlag: 'my',
    });
    var userInfo = wx.getStorageSync('userInfo');
    var formData = {
        uid: userInfo.uid,
    };
    wx.request({
      method: 'POST',
      url: app.globalData.domainXcx + '/my/fuwu/list',
      data: formData,
      timeout: 10000, //接口超时10S
      success: function (res) {
        res = res.data;
        console.log(res);
        if (res.code!=0) {
          wx.showToast({
            title: res.msg, icon: 'none'
          }); return
        }
        that.setData({
          dtotal: res.total,
          dlist: res.data,
        });
      },
      fail: function () {
        console.log('error');
      }
    });
  },

  // 去日常
  toDay: function (e) {
    wx.navigateTo({
      url: '/pages/mys/fwday/index',
    }); return
  },
})